<template>
    <div class="body">
    <div class="texter"></div>
    <div class="Boxed">
      <img
        src="../../assets/img/hong/four/title1.png"
        class="images"
        alt=""
      >
      <!-- 轮播two -->
      <!-- :autoplay="2000" -->
      <van-swipe
        :duration="700"
        :autoplay="5000"
        style="height:11.166667rem;"
        :show-indicators=true
        indicator-color='#597b68'
      >
        <van-swipe-item
          v-for="item in list"
          :key="item.goods_id"
        >
          <ul>
            <li
              v-for="itemr in item"
              :key="itemr.goods_id"
              @click="nav(itemr)"
            >
              <div class="black">
                <img
                  class="one-hit"
                  v-lazy="itemr.goods_img"
                  :key="itemr.goods_img"
                >
                <div class="money-Hot">¥
                  <span>{{itemr.active_price}}</span>
                </div>
              </div>
              <div class="text-one"> {{itemr.goods_name}}</div>
            </li>
          </ul>
        </van-swipe-item>
      </van-swipe>
    </div>
    <div class="boss">
      <img
        src="../../assets/img/hong/four/title2.png"
        alt=""
        class="imge"
      >
      <van-tabs
        type="card"
        animated
        color='#2da175'
        background='transparent'
        title-active-color='#ffffff'
        title-inactive-color='#ffffff'
      >
        <van-tab title="特色美食">
          <div class="add">
            <ul>
              <li
                v-for="item in listtwo"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  class="img"
                  v-lazy="item.goods_img"
                  :key="item.goods_img"
                >
                <div class="textt">
                  {{item.goods_name}}
                </div>
                <div class="moneyy">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
                <img
                  src="../../assets/img/hong/four/gou.png"
                  class="shopping"
                  alt=""
                >
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab title="美颜养护">
          <div class="add">
            <ul>
              <li
                v-for="item in listthree"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  class="img"
                  v-lazy="item.goods_img"
                  :key="item.goods_img"
                >
                <div class="textt">
                  {{item.goods_name}}
                </div>
                <div class="moneyy">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
                <img
                  src="../../assets/img/hong/four/gou.png"
                  class="shopping"
                  alt=""
                >
              </li>
            </ul>
          </div>
        </van-tab>
        <van-tab title="滋补养生">
          <div class="add">
            <ul>
              <li
                v-for="item in listfour"
                :key="item.goods_id"
                @click="nav(item)"
              >
                <img
                  class="img"
                  v-lazy="item.goods_img"
                  :key="item.goods_img"
                >
                <div class="textt">
                  {{item.goods_name}}
                </div>
                <div class="moneyy">
                  ¥
                  <span>{{item.active_price}}</span>
                </div>
                <img
                  src="../../assets/img/hong/four/gou.png"
                  class="shopping"
                  alt=""
                >
              </li>
            </ul>
          </div>
        </van-tab>
      </van-tabs>
    </div>

    <!-- 置顶 -->
    <div
      class="totop"
      id="totop"
      @click="backTop"
      v-show="btnFlag"
    >
    </div>
  </div>
</template>

<script>
import bridge from '../../js/js1'
import { index, Coupondev } from '@/api/index'
import { share } from '../../js/public'
import { getSystem, openApp, getUrlQuery, parseKeyValue } from '../../js/js'
export default {
  // 组件名称
  name: '',
  // 局部注册的组件
  components: {},
  // 组件参数 接收来自父组件的数据
  props: {},
  // 组件状态值
  data () {
    return {
      list: [],
      listtwo: [],
      listthree: [],
      listfour: [],
      system: getSystem(),
      btnFlag: false,
    }
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {},
  destroyed () {
    window.removeEventListener('scroll', this.scrollToTop);
  },
  // 生命周期钩子   注：没用到的钩子请自行删除
  /**
  * 组件实例创建完成，属性已绑定，但DOM还未生成，$ el属性还不存在
  */
  created () {
    this.create()
  },
  /**
  * el 被新创建的 vm.el 替换，并挂载到实例上去之后调用该钩子。
  * 如果 root 实例挂载了一个文档内元素，当 mounted 被调用时 vm.el 也在文档内。
  */
  mounted () {
    window.addEventListener('scroll', this.scrollToTop)
  },
  // 组件方法
  methods: {
    async create () {
      try {
        const res = await index({
          id: 97
        })
        console.log(res.data.data.types);
        var list = res.data.data.types[0].goods
        var resultdev = []
        for (var i = 0; i < list.length; i += 9) {
          resultdev.push(list.slice(i, i + 9));
        }
        this.list = resultdev // 1
        this.listtwo = res.data.data.types[1].goods
        this.listthree = res.data.data.types[2].goods
        this.listfour = res.data.data.types[3].goods
      } catch (err) {
        console.log('错误');
      }
    },
    // 点击图片回到顶部方法，加计时器是为了过渡顺滑
    backTop () {
      const that = this
      let timer = setInterval(() => {
        let ispeed = Math.floor(-that.scrollTop / 5)
        document.documentElement.scrollTop = document.body.scrollTop = that.scrollTop + ispeed
        if (that.scrollTop === 0) {
          clearInterval(timer)
        }
      }, 16)
    },
    // 为了计算距离顶部的高度，当高度大于60显示回顶部图标，小于60则隐藏
    scrollToTop () {
      const that = this
      let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
      that.scrollTop = scrollTop
      // console.log(that.scrollTop);
      if (that.scrollTop > 800) {
        that.btnFlag = true
      } else {
        that.btnFlag = false
      }
    },
    // 跳转下载
    nav (item) {
      console.log(item.goods_id);
      // window.locaition.href = 'http://yuanfuda933.oss-cn-zhangjiakou.aliyuncs.com/yfdMall_1_v1.0.1.apk?squId=' + 'item.goods._id'
      window.location.href = 'yfd://yfdmall:8080/goodsDetail?spuId=' + item.goods_id
    },
    href (uri, blank = true) {
      const a = document.createElement('a')
      a.style.display = 'none'
      a.href = uri
      if (blank) a.setAttribute('target', '_blank')
      document.body.appendChild(a)
      a.click()
      setTimeout(t => {
        document.body.removeChild(a)
      }, 0)
    },
  }
}
</script>

<style scoped lang="less">
.body {
  overflow: hidden;
  min-width: 320px;
  max-width: 750px;
  width: 10rem;
  background: #015848;
  margin: 0 auto;
  line-height: 1.5;
  font-family: Arial, Helvetica;
  .totop {
    position: fixed;
    width: 1.2rem; /* 40/16 */
    height: 1.2rem;
    border-radius: 1.25rem /* 20/16 */;
    opacity: 0.8;
    background: url("../../assets/ding.png") no-repeat;
    background-size: contain;
    box-shadow: 0 1px 5px 0 #e0e0e0;
    right: 0.125rem; /* 18/16 */
    bottom: 3rem; /* 64/16 */
    z-index: 1100;
    -webkit-transition: opacity 0.5s;
    transition: opacity 0.5s;
  }

  .texter {
    width: 10rem;
    height: 14.746667rem;
    background: url("../../assets/img/hong/four/header.png") no-repeat;
    background-size: contain;
  }
  .Boxed {
    width: 9.813333rem;
    height: 13.106667rem;
    margin: -1rem auto 0;
    position: relative;
    border-radius: 0.266667rem;
    box-sizing: border-box;
    padding-top: 1.466667rem;
    background: -webkit-linear-gradient(top, #fdead1, #fed8a6);
    .images {
      width: 100%;
      height: 2.266667rem;
      position: absolute;
      top: 0%;
    }
    .van-swipe {
      width: 9.813333rem;
      overflow: hidden;
    }
    /deep/ .van-swipe__indicators {
      bottom: 0rem;
    }
    /deep/ .van-swipe-item {
      li:nth-child(2) {
        // margin: 0 0.36rem;
      }
      ul li {
        // box-shadow: 0 0.02rem 0.0016667rem 0.0016667rem #e7e7e7;
        float: left;
        width: 3.013333rem;
        height: 3.36rem;
        overflow: hidden;
        background: -webkit-linear-gradient(top, #bce5d2, #486956);
        margin-left: 0.149333rem;
        margin-bottom: 0.266667rem;
        border-radius: 0.35rem;
        border: 0.026667rem solid #ffffff;
        .black {
          box-sizing: border-box;
          border-radius: 0.35rem;
          margin: 0.0713333rem auto;
          width: 2.853333rem;
          height: 2.453333rem;
          background: #ffffff;
        }
        .one-hit {
          border-radius: 0.266667rem;
          margin-top: 0.066667rem;
          margin-left: 0.26rem;
          width: 2.3rem;
          height: 1.8rem;
        }
        .text-one {
          font-size: 0.293333rem;
          color: #ffffff;
          font-weight: 500;
          width: 2.733333rem;
          margin: 0.206667rem auto 0;
          // height: 0.906667rem;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 1;
        }
        .money-Hot {
          width: 2.066667rem;
          height: 0.48rem;
          background: #de5045;
          border-radius: 0.4rem;
          margin: -0.2rem auto 0;
          text-align: center;
          line-height: 0.48rem;
          font-weight: 600;
          font-size: 0.266667rem;
          color: #f9d3aa;
          span {
            color: #fbe1c0;
            font-size: 0.373333rem;
          }
        }
      }
    }
  }
  .boss {
    width: 9.706667rem;
    // height: 6rem;
    background: #fdead1;
    border-radius: 0.266667rem;
    margin: 0.48rem auto;
    position: relative;
    box-sizing: border-box;
    padding-top: 1.76rem;
    padding-bottom: 0.266667rem;
    .imge {
      position: absolute;
      top: 0%;
      width: 100%;
      height: 2.24rem;
    }
    ul {
      li {
        position: relative;
        width: 9.226667rem;
        height: 3.733333rem;
        margin: 0.266667rem auto;
        background: #ffffff;
        border-radius: 0.266667rem;
        img {
          width: 3.493333rem;
          height: 3.253333rem;
          border-radius: 0.266667rem;
          margin-left: 0.133333rem;
          margin-top: 0.24rem;
        }
        .text {
          float: right;
          width: 5.333333rem;
          // height: 1.066667rem;
          margin-top: 0.64rem;
          margin-right: 0.106667rem;
          font-size: 0.453333rem;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
        }
        .money {
          position: absolute;
          right: 5%;
          bottom: 10%;
          width: 4.826667rem;
          height: 0.88rem;
          background: url("../../assets/img/hong/two/gou.png") no-repeat;
          background-size: contain;
          font-size: 0.373333rem;
          color: #ffffff;
          box-sizing: border-box;
          padding-left: 0.333333rem;
          span {
            font-size: 0.533333rem;
          }
        }
      }
    }
    .van-tabs--card /deep/ .van-tabs__wrap {
      height: 0.96rem;
      width: 9.36rem;
      border: 0;
      border-radius: 0.466667rem;
      background: #a0dfb5;
      margin: 0 auto;
      // 状态栏
      .van-tabs__nav--card {
        border: 0;
        height: 100%;
        // 每一格
        .van-tab {
          height: 100%;
          border-right: 0;
          // margin-top: 0.1266667rem;
        }
        // 选中格
        .van-tab.van-tab--active {
          border-radius: 0.6rem;
          border: 0;
          .van-tab__text--ellipsis {
            font-weight: 600;
          }
        }
      }
    }
    .add {
      width: 9.653333rem;
      margin: 0.133333rem auto;
      border-radius: 0.4rem;
      position: relative;
      overflow: hidden;
      box-sizing: border-box;
      ul {
        li {
          float: left;
          width: 4.56rem;
          height: 6.64rem;
          border-radius: 0.166667rem;
          background: #ffffff;
          margin-bottom: 0.266667rem;
          margin-left: 0.186667rem;
          position: relative;
          .shopping {
            position: absolute;
            right: 6%;
            bottom: 4%;
            width: 0.8rem;
            height: 0.8rem;
          }
          .img {
            width: 3.493333rem;
            height: 3.173333rem;
            margin-top: 0.773333rem;
            margin-left: 0.506667rem;
          }
          .textt {
            margin: 0.206667rem auto 0;
            width: 3.093333rem;
            height: 1.033333rem;
            font-weight: 600;
            font-size: 0.373333rem;
            color: #333333;
            overflow: hidden;
            text-overflow: ellipsis;
            display: -webkit-box;
            -webkit-box-orient: vertical;
            -webkit-line-clamp: 2;
          }
          .moneyy {
            margin-left: 0.646667rem;
            // width: 1.333333rem;
            // height: 0.426667rem;
            font-size: 0.373333rem;
            color: #ff301e;
            span {
              font-size: 0.613333rem;
            }
          }
        }
      }
    }
  }
}
@keyframes mymove {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}
@-webkit-keyframes mymove /*Safari and Chrome*/ {
  0% {
    transform: scale(1); /*开始为原始大小*/
  }
  25% {
    transform: scale(1.1); /*放大1.1倍*/
  }
  50% {
    transform: scale(1);
  }
  75% {
    transform: scale(1.1);
  }
}
</style>
